package cn.zyx.service.impl;



import cn.zyx.Config.Result;
import cn.zyx.dao.CreditDao;
import cn.zyx.entity.Credit;
import cn.zyx.service.CreditService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * (Credit)表服务实现类
 *
 * @author makejava
 * @since 2022-01-03 16:10:41
 */
@Service("creditService")
public class CreditServiceImpl implements CreditService {
    @Resource
    private CreditDao creditDao;

    /**
     * 通过运营商查询多条数据
     * @param operator 运营商编号
     * @return
     */
    @Override
    public List<Credit> queryByOp(Integer operator) {
        return this.creditDao.queryByOp(operator);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Credit queryById(Integer id) {
        return this.creditDao.queryById(id);
    }

    /**
     * 查询全部数据
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @param operator
     * @return
     */
    @Override
    public Result queryAllByLimit(int offset, int limit, Integer operator) {
        long getcount = creditDao.getcount(operator);
        List<Credit> credits = creditDao.queryAllByLimit(offset, limit, operator);
        Result result=new Result(0,"查询成功",credits,getcount);
        return result;
    }


    @Override
    public List<Credit> queryAll(Credit credit) {
        return this.creditDao.queryAll(credit);
    }

    /**
     * 新增数据
     *
     * @param credit 实例对象
     * @return 实例对象
     */
    @Override
    public Credit insert(Credit credit) {
        this.creditDao.insert(credit);
        return credit;
    }

    /**
     * 修改数据
     *
     * @param credit 实例对象
     * @return 实例对象
     */
    @Override
    public Credit update(Credit credit) {
        this.creditDao.update(credit);
        return this.queryById(credit.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.creditDao.deleteById(id) > 0;
    }
}